package com.shen.webbf.cxf;

import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

/**
 * 
* <p>Title:CxfCilent </p>
* <p>Description: cxf 客户端 </p>
* @author shenhx
* @date 2017-5-11 下午2:34:13
 */
public class CxfCilent {
	
	/**
	 * 
	 * 说明：调用 webservice 客户端方法
	 * @author shenhx
	 * @date 2017-5-11 下午2:44:25
	 * 
	 * @param wsdlPath webservice 地址
	 * @param params webservice 参数
	 * @param wsMethod webservice 具体方法
	 * @return 返回值 String 格式
	 * @throws Exception 调用异常
	 */
	public String testClient(String wsdlPath, Object[] params, String wsMethod) throws Exception{
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 
	    org.apache.cxf.endpoint.Client client = dcf.createClient(wsdlPath); 
	    
	    //设置请求时间 10000000 毫秒，防止请求超时
	    HTTPConduit conduit = (HTTPConduit)client.getConduit();  
	    HTTPClientPolicy policy = new HTTPClientPolicy();  
	    policy.setAllowChunking(false);
	    policy.setReceiveTimeout(10000000);
	    conduit.setClient(policy);
	            
	    //Object[] params = new Object[] { "内蒙古自治区高级人民法院", "最高人民法院" }; 
	    //1、获取所有组织机构信息
    	Object[] objects = client.invoke(wsMethod, params);
    	String xmlString = objects[0].toString();
        
    	return xmlString;
	}

}
